package cn.wsalix.biz.entity;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import cn.anlaser.entity.CommonEntity;
import cn.wsalix.biz.type.CatTypeEnum;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "RELATION_CAT")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@EntityListeners({ AuditingEntityListener.class })
@Data
@EqualsAndHashCode(exclude = { "category" }, callSuper = false)
@ToString(exclude = { "category" })
public class RelationCat extends CommonEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4900208128806262394L;
	private Long fkId;
	private CatTypeEnum catType;
	@JsonIgnore
	@ManyToOne(cascade = CascadeType.MERGE, optional = true, fetch = FetchType.LAZY)
	@JoinColumn(foreignKey = @ForeignKey(name = "FK_RELATION_CAT"), name = "CAT_ID")
	private Category category;
}